home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 1 / Macwelt DVD 1.toast / Web-Publishing / HTML-Editoren / Alpha ƒ / Tcl / SystemCode / CorePackages / aeprint.tcl < prev    next >
Encoding:
Text File  |  2000-10-28  |  5.2 KB  |  178 lines

  1. ## -*-Tcl-*-
  2.  # ###################################################################
  3.  #  TclAE - AppleEvent extension for Tcl
  4.  # 
  5.  #  FILE: "aeprint.tcl"
  6.  #                                    created: 8/22/99 {4:59:36 PM} 
  7.  #                                last update: 10/28/00 {10:37:00 PM} 
  8.  #  Author: Jonathan Guyer
  9.  #  E-mail: jguyer@his.com
  10.  #    mail: Alpha Cabal
  11.  #          POMODORO no seisan
  12.  #     www: http://www.his.com/jguyer/
  13.  #  
  14.  # ========================================================================
  15.  #               Copyright (c) 1999-2000 Jonathan Guyer
  16.  #                        All rights reserved
  17.  # ========================================================================
  18.  # Permission to use, copy, modify, and distribute this software and its
  19.  # documentation for any purpose and without fee is hereby granted,
  20.  # provided that the above copyright notice appear in all copies and that
  21.  # both that the copyright notice and warranty disclaimer appear in
  22.  # supporting documentation.
  23.  # 
  24.  # Jonathan Guyer disclaims all warranties with regard to this software,
  25.  # including all implied warranties of merchantability and fitness.  In
  26.  # no event shall Jonathan Guyer be liable for any special, indirect or
  27.  # consequential damages or any damages whatsoever resulting from loss of
  28.  # use, data or profits, whether in an action of contract, negligence or
  29.  # other tortuous action, arising out of or in connection with the use or
  30.  # performance of this software.
  31.  # ========================================================================
  32.  #  Description: 
  33.  #  
  34.  #   Routines to print TclAE descriptors into AEGizmo form.
  35.  # 
  36.  #  History
  37.  # 
  38.  #  modified   by  rev reason
  39.  #  ---------- --- --- -----------
  40.  #  1999-08-22 JEG 1.0 original
  41.  # ###################################################################
  42.  ##
  43.  
  44. namespace eval tclAE::print {}
  45.  
  46. proc tclAE::loadprint {} {}
  47.  
  48. if {([info tclversion] < 8.0)
  49. ||    ![info exists tclAE_version] 
  50. ||  ($tclAE_version < 2.0)} {
  51.     
  52. proc tclAE::desc::_****_print {theAEDesc} {
  53.     global $theAEDesc
  54.     
  55.     set type [set ${theAEDesc}(descriptorType)]
  56.     set data [set ${theAEDesc}(dataRecord)]
  57.     
  58.     if {[tclAE::desc::isDescriptor $data]} {
  59.         return "${type}\([tclAE::print ${data}]\)"
  60.     } else {
  61.         return "${type}\([tclAE::build::hexd $data]\)"
  62.     }
  63. }
  64.  
  65. proc tclAE::desc::_list_print {listAEDesc} {
  66.     global $listAEDesc
  67.     
  68.     set out {}
  69.     foreach item [set ${listAEDesc}(dataRecord)] {
  70.         lappend out [tclAE::print $item]
  71.     }
  72.     
  73.     set out [join $out ", "]
  74.     return "\[${out}\]"
  75. }
  76.  
  77. proc tclAE::desc::_hexd_print {hexdAEDesc} {
  78.     global $hexdAEDesc
  79.     return [tclAE::build::hexd [set ${hexdAEDesc}(dataRecord)]]
  80. }
  81.  
  82. proc tclAE::desc::_long_print {longAEDesc} {
  83.     global $longAEDesc
  84.     
  85.     binary scan [set ${longAEDesc}(dataRecord)] I long
  86.     return $long
  87. }
  88.  
  89. proc tclAE::desc::_shor_print {shorAEDesc} {
  90.     global $shorAEDesc
  91.     
  92.     binary scan [set ${shorAEDesc}(dataRecord)] S shor
  93.     return $shor
  94. }
  95.  
  96. proc tclAE::desc::_TEXT_print {TEXTAEDesc} {
  97.     global $TEXTAEDesc
  98.     
  99.     set TEXT [set ${TEXTAEDesc}(dataRecord)]
  100.     
  101.     if {[string length $TEXT] == 0} {
  102.          return "[tclAE::build::coercion {} TEXT]"
  103.     } else {
  104.         set firstNull [string first "00" $TEXT]
  105.         set firstOpenCurly [string first "D2" $TEXT]
  106.         set firstCloseCurly [string first "D3" $TEXT]
  107.         
  108.         if {($firstNull > 0 && [expr {$firstNull % 2}] == 0)
  109.         ||    ($firstOpenCurly > 0 && [expr {$firstOpenCurly % 2}] == 0)
  110.         ||    ($firstCloseCurly > 0 && [expr {$firstCloseCurly % 2}] == 0)} {
  111.             # AEGizmos string rep can't handle \x00, “, or ”.
  112.             return [tclAE::build::coercion [tclAE::build::hexd $TEXT] TEXT]
  113.         } else {
  114.             binary scan $TEXT a* text
  115.             return "“${text}”"
  116.         }
  117.     }
  118.     
  119. }
  120.  
  121. proc tclAE::desc::_enum_print {enumAEDesc} {
  122.     global $enumAEDesc
  123.     
  124.     binary scan [set ${enumAEDesc}(dataRecord)] a4 enum
  125.     return [tclAE::build::protect $enum]
  126. }
  127.  
  128. ## 
  129.  # -------------------------------------------------------------------------
  130.  # 
  131.  # "tclAE::desc::_reco_print" --
  132.  # 
  133.  #  Convert descriptor to an AE record, i.e., "{t1:l1, t2:l2, t3:l3, ...}".
  134.  # -------------------------------------------------------------------------
  135.  ##
  136. proc tclAE::desc::_reco_print {theAERecord} {
  137.     global $theAERecord
  138.     
  139.     set out {}    
  140.     foreach keyword [set ${theAERecord}(dataRecord)] {
  141.         set pair [tclAE::build::protect $keyword]
  142.         append pair ":" [tclAE::print [set ${theAERecord}($keyword)]]
  143.         lappend out $pair
  144.     }
  145.     
  146.     set out [join $out ", "]
  147.     
  148.     set descriptorType [set ${theAERecord}(descriptorType)]
  149.     if {($descriptorType == "reco")
  150.     ||  ($descriptorType == "aevt")} {
  151.         return "\{${out}\}"    
  152.     } else {
  153.         return "[tclAE::build::protect $descriptorType]\{${out}\}"    
  154.     }
  155. }
  156.  
  157. proc tclAE::desc::_aevt_print {theAppleEvent} {
  158.     global $theAppleEvent
  159.     
  160.     set out [set ${theAppleEvent}(evcl)]
  161.     append out "\\" [set ${theAppleEvent}(evid)]
  162.     append out [tclAE::desc::_reco_print $theAppleEvent]
  163.  
  164.     return $out
  165. }
  166.  
  167. set tclAE::desc::procs(hexd.print)            tclAE::desc::_hexd_print
  168. set tclAE::desc::procs(shor.print)            tclAE::desc::_shor_print
  169. set tclAE::desc::procs(long.print)            tclAE::desc::_long_print
  170. set tclAE::desc::procs(TEXT.print)            tclAE::desc::_TEXT_print
  171. set tclAE::desc::procs(enum.print)            tclAE::desc::_enum_print
  172. set tclAE::desc::procs(reco.print)            tclAE::desc::_reco_print
  173. set tclAE::desc::procs(aevt.print)            tclAE::desc::_aevt_print
  174.  
  175.  
  176. }
  177.  
  178.